/**
 * 
 */
package br.ufpe.cin.mac.middleware.autonomic;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author Osmany
 * 
 */
public class Config {

	private List<String> interceptors;

	private Calendar calendar;

	private Map<String, Float> values;

	public Config() {
		interceptors = new LinkedList<String>();
		values = new HashMap<String, Float>();
	}

	public boolean compareInterceptors(List<String> interceptors) {
		if (interceptors.size() == this.interceptors.size()) {
			Iterator<String> it = interceptors.iterator();
			while (it.hasNext()) {
				String interceptor = it.next();
				if (!this.interceptors.contains(interceptor)) {
					return false;
				}
			}
		}
		return true;
	}

	/**
	 * @return the calendar
	 */
	public Calendar getCalendar() {
		return calendar;
	}

	/**
	 * @param calendar
	 *            the calendar to set
	 */
	public void setCalendar(Calendar calendar) {
		this.calendar = calendar;
	}

	/**
	 * Update calendar to current value
	 */
	public void updateCalendar() {
		this.calendar = Calendar.getInstance();
	}

	/**
	 * @return the interceptors
	 */
	public List<String> getInterceptors() {
		return interceptors;
	}

	/**
	 * @param interceptors
	 *            the interceptors to set
	 */
	public void setInterceptors(List<String> interceptors) {
		this.interceptors = interceptors;
	}

	/**
	 * @return the values
	 */
	public Map<String, Float> getValues() {
		return values;
	}

	/**
	 * @param values
	 *            the values to set
	 */
	public void setValues(Map<String, Float> values) {
		this.values = values;
	}

	/**
	 * @param e
	 * @return
	 * @see java.util.List#add(java.lang.Object)
	 */
	public boolean addInterceptor(String e) {
		return interceptors.add(e);
	}

	/**
	 * @param index
	 * @return
	 * @see java.util.List#get(int)
	 */
	public String getInterceptor(int index) {
		return interceptors.get(index);
	}

	/**
	 * @param key
	 * @return
	 * @see java.util.Map#get(java.lang.Object)
	 */
	public float getValue(String key) {
		return values.get(key);
	}

	/**
	 * @param key
	 * @param value
	 * @return
	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
	 */
	public float putValue(String key, float value) {
		// System.out.println("putValue: " + value);
		// System.out.println(values);
		// System.out.println(key);
		try {
			return values.put(key, new Float(value));
		} catch (Exception e) {
			// e.printStackTrace();
			return 0;
		}
	}
	
	public boolean contaisInterceptor(String interceptor){
		return this.interceptors.contains(interceptor);
	}

}
